package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.SettingsMapper;
import com.tanhua.common.pojo.Settings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: you
 * @Date: 2021/06/08/16:21
 * @Description:
 */
@Service
public class SettingsService {
    @Autowired
    private SettingsMapper settingsMapper;


    public Settings querySettings(Long userId) {

        QueryWrapper<Settings> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return settingsMapper.selectOne(queryWrapper);
    }

    public Boolean saveSettings(Settings newSettings) {
        return settingsMapper.insert(newSettings) > 0;
    }

    public Boolean updateSettings(Settings newSettings) {
        try {
            settingsMapper.updateById(newSettings);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }
}
